﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace MonitorProvider.Prototype.FileReader
{
    public enum FileType
    {
        TXT=0,
        XLS=1
    }
    public class FileReaderFactory
    {
        public static FileReaderBase Create(FileType fileType, string providerName)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string typeName = string.Format("MonitorProvider.Prototype.FileReader.{0}{1}FileReader", providerName, fileType.ToString().ToUpper());
            Type type = assembly.GetType(typeName);
            FileReaderBase instance = null;
            if (type.IsSubclassOf(typeof(FileReaderBase)))
            {
                instance = Create(fileType, type);
            }
            if (instance == null)
            {
                typeName = string.Format("MonitorProvider.Prototype.FileReader.{0}{1}FileReader", "Default", "TXT");
                type = assembly.GetType(typeName);
                instance = Create(fileType, type);
            }
            return instance;
        }

        public static FileReaderBase Create(FileType fileType,  Type type)
        {
            //Assembly assembly = Assembly.GetExecutingAssembly();
           // string typeName = string.Format("MonitorProvider.Prototype.FileReader.{0}{1}FileReader");
            object instance = Activator.CreateInstance(type);
            return instance as FileReaderBase;
        }

    }
}
